#!/usr/bin/env python 

#+_+ coding:utf-8 +_+

import httplib
import urllib
import hashlib

def md5(*args):
    md5Ctx = hashlib.md5()
    for arg in args:
        md5Ctx.update(str(arg))
    return md5Ctx.hexdigest()


title = "title"
content = "content"
uid = 1
author="cz"
ticket   = "bd637611abfe504f1ad40547af91687f"
contents = [title,content,str(uid),ticket,author]

contents = sorted(contents)
signature = md5(*contents)

params = dict(uid=uid,signature=signature,title=title,content=content,author=author)

req  = urllib.urlencode(params)  

headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}  

httpClient = httplib.HTTPConnection("localhost", 8080, timeout=30)
httpClient.request("POST", "/apping/demo/postnews", req, headers)

response = httpClient.getresponse() 

print response.status  
print response.reason  
print response.read()  

